package com.spa.modules.gen.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Maps;
import com.spa.modules.gen.entity.GenTable;
import com.spa.modules.gen.entity.GenTableColumn;
import com.spa.modules.gen.mapper.GenDataBaseDictMapper;

/**
 * 基础数据
 * @author Administrator
 *
 */
@Service
@Transactional(readOnly = true)
public class GenDataBaseDictService {

	@Autowired
	private GenDataBaseDictMapper genDataBaseDictDao;
	
	/**
	 * 数据库全表信息
	 * @param genTable
	 * @return
	 */
	public List<GenTable> findTableList(String tableName){
		List<GenTable> list = genDataBaseDictDao.findTableList(tableName);
		return list;
	}
	
	/**
	 * 查询数据库表字段信息
	 * @param genTable
	 * @return
	 */
	public List<GenTableColumn> findTableColumnList(String tableName){
		List<GenTableColumn> genTableColumnList = genDataBaseDictDao.findTableColumnList(tableName);
		List<String> pkList = genDataBaseDictDao.findTablePK(tableName);
		Map<String, Object> pkMap = Maps.newHashMap();
		for(String pk:pkList) {
			pkMap.put(pk, pk);
    	}
		for(GenTableColumn genTableColumn:genTableColumnList) {
			if(pkMap.get(genTableColumn.getName()) != null) {
				genTableColumn.setIsPk("1");
			}
		}
		return genTableColumnList;
	}

}
